﻿Type.registerNamespace("EcmaDoc");

EcmaDoc.Frames = function Frames()
{
}

EcmaDoc.Frames.setup = function Frames$setup()
{
	$evt.addListener($("#sizer"), "onmousedown", EcmaDoc.Frames.onSizerMouseDown);
	$evt.addListener($$("#switches .switch"), "onclick", EcmaDoc.Frames.onSwitchClick);
}

EcmaDoc.Frames.onSwitchClick = function Frames$onSwitchClick(e)
{
	var switches = $$("#switches .switch");
	for (var i = 0; i < switches.length; i++)
	{
		if (switches[i].id.match(/switch_(.*)/))
		{
			var name = RegExp.$1;
			var frame = $("#{0}_frame".format(name));

			if (switches[i] == this)
			{
				$css.addClass(frame, "active");
				$css.addClass(switches[i], "active");
			}
			else
			{
				$css.removeClass(frame, "active");
				$css.removeClass(switches[i], "active");
			}
		}
	}
}

EcmaDoc.Frames.onSizerMouseDown = function Frames$onSizerMouseDown(e)
{
	$drag.addListener("ondragmove", EcmaDoc.Frames.onSizerDragMove);
	return $drag.start(e, this, true, false);
}

EcmaDoc.Frames.onSizerDragMove = function Frames$onSizerDragMove(evt)
{
	if (evt.data.targetX < 50)
	{
		evt.data.targetX = 50;
		return;
	}

	$css.pixelWidth($("#toc"), evt.data.targetX);
	$css.pixelLeft($("#main"), evt.data.targetX + $("#sizer").offsetWidth);
}

$evt.addListener(window, "onload", EcmaDoc.Frames.setup);
